The Conversions object contains the following methods:
The ConvertValue method converts the provided value from its source units to the destination units.
ConvertValue(Value As Integer, UnitsSource As String, UnitsDestination As String) As String
| Parameter | Required | Description |
|---|---|---|
|
Value |
Yes |
The original number to be converted. |
|
UnitsSource |
Yes |
The unit name that Value is in. |
|
UnitsDestination |
Yes |
The unit name that Value will be converted to. |
Return Value: Value after it has been converted into UnitsDestination.
Example
The following method converts 9001 centimeters to meters.
|
Sub conValue() Dim objConversion Set objConversion = CreateObject("CxScript.Conversions")
Dim iRet, iValue, strSource, strDest iValue = 9001 strSource = "cm" strDest = "m" iRet = objConversion.ConvertValue(ivlaue, strSource, strDest) edtMessageBox.Text = iValue & strSource & " is equal to " & iRet & strDest End Sub |
The GetAllCategories method returns a list of all unit categories by their integer identifier. It does not return the category name string. GetCategoryName can be used in conjunction to get a human-readable name.
GetAllCategories() As Variant
Return Value: List of all unit categories by their integer identifier.
Example
The following example retrieves all unit category IDs, category names, units for each category, and the unit descriptions.
|
Dim objConversions Set objConversions = CreateObject ("CxScript.Conversions")
' get all unit category IDs Dim arrCategories arrCategories = objConversions.GetAllCategories
Dim strUnit Dim strUnitDesc Dim arrUnits Dim nCategory Dim strCategoryName
For Each nCategory In arrCategories ' now that we have the ID for the category, get its name strCategoryName = objConversions.GetCategoryName(nCategory)
' get the units for this category arrUnits = objConversions.GetUnitsForCategory(nCategory)
For Each strUnit In arrUnits strUnitDesc = objConversions.GetUnitDescription(strUnit)
' TODO: store category ID, category name, unit name, and unit description Next Next |
The GetAllUnitNames method retrieves all valid unit names (optionally abbreviates them).
GetAllUnitNames(Abbreviate As Boolean) As Variant
| Parameter | Required | Description |
|---|---|---|
|
Abbreviate |
Yes |
Set to True to abbreviate all the unit names, False to return the full names. |
Return Value: An array of all unit names.
Example
The following example gets the unabbreviated names of all units and displays them in a list box.
|
Sub getUnitNames() Dim arrNames, item, objConversion Set objConversion = CreateObject("CxScript.Conversions")
arrNames = objConversion.GetAllUnitNames(False) For Each item In arrNames lstUnits.AddString(item) Next End Sub |
The GetGategoryName method returns the name for the provided unit category identifier.
GetCategoryName(Category As Integer) As String
| Parameter | Required | Description |
|---|---|---|
|
Category |
Yes |
The unit category name string. |
Return Value: The human-readable name of the unit category.
Example
See the example for GetAllCategories.
The GetConvertableUnitNames method retrieves all unit names to which the provided unit name can be converted.
GetConvertableUnitNames(Units As String, Abbreviate As Boolean) As Variant
| Parameter | Required | Description |
|---|---|---|
|
Units |
Yes |
A valid unit name. |
|
Abbreviate |
Yes |
Set to True to abbreviate the unit names, False to return the full names. |
Return Value: An array of all convertible unit names. If Units is invalid, an empty array is returned.
Example
The following example gets all the units that meters can be converted into.
|
Sub getConvertableNames() Dim arrNames, item, objConversion Set objConversion = CreateObject("CxScript.Conversions")
arrNames = objConversion.GetConvertableUnitNames("meters", False) For Each item In arrNames lstUnits.AddString(item) Next End Sub |
The GetUnitDescription method returns the long name for a given unit. For example, providing "m" will return "meters".
GetUnitDescription(Unit As String) As String
| Parameter | Required | Description |
|---|---|---|
|
Unit |
Yes |
The abbreviated unit. |
Return Value: The long name of the given unit.
Example
See the example for GetAllCategories.
The GetUnitsForCategory method returns a list of all units for the provided unit category. The unit name as a string will be in the returned array.
GetUnitsForCategory(Category As Integer) As Variant
| Parameter | Required | Description |
|---|---|---|
|
Category |
Yes |
The unit category name string. |
Return Value: An array of all unit names.
Example
See the example for GetAllCategories.
The IsConvertable method determines if there is a valid conversion between the provided unit names.
IsConvertable(UnitsSource As String, UnitsDestination As String) As Boolean
| Parameter | Required | Description |
|---|---|---|
|
UnitsSource |
Yes |
A valid unit name. The method will test if this parameter can be converted into UnitsDestination. |
|
UnitsDestination |
Yes |
This method will test if UnitsSource can be converted into this unit name. |
Return Value: A Boolean indicating whether the two units are convertible.
Example
The following example checks if meters is convertible to kilometers.
|
Sub isConvertible() Dim objConversion Set objConversion = CreateObject("CxScript.Conversions")
Msgbox objConversion.isConvertable("meters", "kilometers") 'Returns True End Sub |
The SetBarAirPressure method overrides the conversion library’s default air pressure value used to convert from gauge to absolute pressure.
SetBarAirPressure(BarAirPressure As Double)
| Parameter | Required | Description |
|---|---|---|
|
BarAirPressure |
Yes |
The new value to set for air pressure. |
Example
The following example sets the barometric air pressure to 1.0132 bars.
|
Sub setBarPressure() Dim objConversion Set objConversion = CreateObject("CxScript.Conversions")
objConversion.SetBarAirPressure(1.01320) edtMessageBox.Text = "Bar pressure set" End Sub |